package org.lionsoul.websnail.worker;

import org.lionsoul.websnail.task.Task;

/**
 * spider worker interface
 *
 * @author chenxin<chenxin619315 @ gmail.com>
 */
public interface Worker {
    int READY = 0;
    int RUNNING = 1;
    int PAUSED = 2;
    int STOPPED = 3;

    /**
     * get the task number of the task queue
     */
    public int getLeftTask();

    /**
     * add a new task to the task queue
     */
    public boolean addTask(Task task);

    /**
     * get the available thread of the current worker
     *
     * @return int
     */
    public int getAvailableThread();

    /**
     * get the current working thread for the worker
     */
    public int getWorkingThread();

    /**
     * weather could accept more task
     *
     * @return boolean
     */
    public boolean couldHoldMore();

    /**
     * accept the specified task
     *
     * @return boolean
     */
    public boolean process(Runnable task);

    /**
     * get the current working state
     */
    public int getState();

    /**
     * start the worker
     */
    public void start();

    /**
     * pause the worker
     */
    public void pause();

    /**
     * resume the worker
     */
    public void resume();

    /**
     * shutdown the worker
     */
    public void shutdown();
}
